package com.woniuxy.exchangeType.topic;

import com.rabbitmq.client.BuiltinExchangeType;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import com.woniuxy.utils.Utils;

import java.io.IOException;
import java.util.concurrent.TimeoutException;

/**
 * 持久化： 交换机持久化  队列持久化  消息持久化（生产者在生成的时候需要消息持久化）
 */
public class TopicDeclare {
    public static void main(String[] args) throws IOException, TimeoutException {
        //获取连接
        Connection connection = Utils.getConnection();
        //建立通道
        Channel channel = connection.createChannel();
        //建立交换机  并持久化
        channel.exchangeDeclare("topicExchange", BuiltinExchangeType.TOPIC,true);
        //建立队列   并持久化
        channel.queueDeclare("topicQueue1",true,false,false,null);
        channel.queueDeclare("topicQueue2",true,false,false,null);
        //交换机绑定队列 topic模式 交换机绑定队列的时候可以使用通配符 .表示一个单词   #表示一个或者多个单词
        channel.queueBind("topicQueue1","topicExchange","*.topic.*");
        channel.queueBind("topicQueue2","topicExchange","topic.*");
        channel.queueBind("topicQueue2","topicExchange","topic.#");
        //关闭资源
        channel.close();
        connection.close();
    }
}
